
import time, datetime
from pymongo import MongoClient
from bson import ObjectId
import pymysql
import traceback
import copy

dbs = {
    "mongo-dev": {
        "host": "10.246.247.236",
        "port": 27016,
        "username": "dev_xhhkmedical",
        "password": "h4wgrd1Q9rCaaVu0",
        "authSource": "dev_xhhkmedical"
    },
    "mongo-prod": {
        "host": "10.246.247.236",
        "port": 27016,
        "username": "xhhkmedical_readWrite",
        "password": "MM5Mks2Yz0F1qDeh",
        "authSource": "xhhkmedical"
    }
}

mongodb_ins = MongoClient(**dbs["mongo-prod"]).xhhkmedical


def do_biz():
    appcs = mongodb_ins.XHHK_AppConfig.find({"code": "CONNECT_CONFIG", "endpoint": "http://10.246.247.223:8000/prod/a109/"})

    # compare....
    for pp in appcs:
        if not (pp.get("protocol") == "XHHK" and pp.get("services") and ("C0P01" in pp.get("services")) \
                and pp["services"]["C0P01"]["path"] == "xhhk/services/wlpt/v1/WL/cardSignNewPatient"):
            continue
        new_services = copy.deepcopy(pp["services"])
        new_services["C0P01"]["url_path"] = "http://a562:8080/ycjcsq/cardSignNewPatient"
        # new_services["C0P01"].pop("url_path")
        mongodb_ins.XHHK_AppConfig.update_one({"_id": pp.get("_id")}, {"$set": {"services": new_services}})


def main():
    try:
        do_biz()
    except Exception:
        print(traceback.format_exc())

if __name__ == '__main__':
    main()
